package com.pms.utils;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * cookie manage
 * @author huyinsong
 *
 */
public class CookieManage {
	/**
	 * set cookie
	 * @param resp HttpServletResponse 
	 * @param c	cookie
	 */
	public void setCookie(HttpServletResponse resp,Cookie c){
		if(c!=null){
			resp.addCookie(c);
		}
		
	}
	/**
	 * get cookies map
	 * @param req HttpServletRequest
	 * @return Map<String,Cookie>
	 */
	public Map<String,Cookie> getCookies(HttpServletRequest req){
		Map<String,Cookie> map=new HashMap<String,Cookie>();
		Cookie[] cookies=req.getCookies();
		if(cookies!=null){
			for(int i=0;i<cookies.length;i++){
				map.put(cookies[i].getName(), cookies[i]);
			}
		}
		return map;
	}

}
